/**
 * Created by zzy on 2017/9/26.
 */
import React, {Component} from 'react';
import {
    Text,
    View,
    TouchableOpacity,
    Image,
    StyleSheet,
    PixelRatio,
    Dimensions,
    FlatList,
    InteractionManager
} from 'react-native';
import NetRequestLuo from '../util/NetRequest'
import MyTicketCell from '../homeLuo/MyTicketCell'
import Ionicons from 'react-native-vector-icons/Ionicons'

export default class MyTiketsLuo extends Component{
    static navigationOptions = {
        header: ()=>{
            return  null
        }
    };
    constructor(props){
        super(props);
        this.state={
            loading:true,
            tiketList:[]
        }
    }
    render(){
        return <View style={{flex:1}}>
            <View style={{flexDirection:'row',alignItems:'center',justifyContent:'space-between',backgroundColor: 'white'}}>
                <TouchableOpacity activeOpacity={1}
                                  onPress={()=>{
                                      this.props.navigation.goBack()
                                  }}>
                    <Ionicons name="ios-arrow-back" size={30} style={{padding:10}}/>
                </TouchableOpacity>
                <Text style={{fontSize:17}}>水票</Text>
                <Text style={{padding:10}} onPress={()=>{this.props.navigation.navigate('MyTicketRecord')}}>账单</Text>
            </View>
            <FlatList
                refreshing={this.state.loading}
                onRefresh={this._onRefresh.bind(this)}
                data={this.state.tiketList}
                keyExtractor={(item,index) => index}
                renderItem={({item})=><MyTicketCell data={item} callback={()=>{
                    this.props.navigation.navigate('MyTicketDetail',{tiket:item});
                }}/>}
            />
        </View>
    }
    componentDidMount(){
        this.tiketList();
    }
    _onRefresh(){
        this.tiketList();
    }
    tiketList(){
        let param={
        };
        InteractionManager.runAfterInteractions(()=> {
            NetRequestLuo.userWaterTicketModelList(param).then((data)=>{
                LOG('水票列表----------'+JSON.stringify(data));
                var tikets=[];
                for(var i=0;i<data.userWaterTicketModelList.length;i++){
                    if(data.userWaterTicketModelList[i].status=='未使用'){
                        tikets.push(data.userWaterTicketModelList[i])
                    }
                }
                this.setState({
                    tiketList: tikets,
                    loading:false
                })
            }).catch(err=>{
                this.setState(
                    {
                        loading:false
                    }
                );
                this.props.navigation.navigate('Login');
            })
        })
    }
}